package com.huike.xingxing.fragment;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.huike.xingxing.MainActivity;
import com.huike.xingxing.R;
import com.huike.xingxing.activity.DailyStatusActivity;
import com.huike.xingxing.activity.MyDescActivity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class MyFragment extends BaseFragment {
    private Context context;
    private LinearLayout ll_my_inform;
    private LinearLayout ll_my_exitapp;
    private LinearLayout ll_my_status;
    private View view;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getActivity();
        //获取缓存判断角色

    }

    private void initData() {
        SharedPreferences userIfno = context.getSharedPreferences("user_ifno", context.MODE_PRIVATE);
        String data = userIfno.getString("data", null);
        Log.e("---",data);
        if(!TextUtils.isEmpty(data)){
            if(data.equals("student")){
                ll_my_status.setVisibility(View.VISIBLE);
            }else{
                ll_my_status.setVisibility(View.GONE);

            }
        }



    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = View.inflate(context, R.layout.my_setting, null);
        initView();
        iniClick();
        initData();
        return view;
    }

    private void iniClick() {
        //退出APP点击
        ll_my_exitapp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setTitle("提示");
                builder.setMessage("确定要退出到登陆界面吗！");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(context, MainActivity.class);
                        // TODO 设置为 SingleTask 模式启动
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
                    }
                });
                builder.setNegativeButton("取消",null);
                builder.show();
            }
        });

        //点击居然详细页面
        ll_my_inform.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(context, MyDescActivity.class));
            }
        });
        //进入每日状态
        ll_my_status.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DailyStatusActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initView() {
        ll_my_inform = view.findViewById(R.id.ll_my_inform);
        ll_my_exitapp = view.findViewById(R.id.ll_my_exitapp);
        ll_my_status = view.findViewById(R.id.ll_my_status);
    }


}
